package com.bluedot.www.core.common.algorithm;

/**
 * @author He Peng
 * @version 1.0
 * @date 2021/9/2 20:11
 */

import javax.tools.SimpleJavaFileObject;
import java.io.IOException;
import java.net.URI;

/**
 * 待编译对象 存储待编译的字符串
 */
public class JavaSourceFileObject extends SimpleJavaFileObject {

    /**
     * 表示java源代码
     **/
    private final CharSequence content;

    public JavaSourceFileObject(String className, String content) {
        super(URI.create("string:///" + className.replaceAll("\\.", "/") + Kind.SOURCE.extension), Kind.SOURCE);
        this.content = content;
    }

    /**
     * 获取需要编译的源代码
     *
     * @param ignoreEncodingErrors:
     * @return java.lang.CharSequence
     * @author He Peng
     * @date 2021/9/2 20:12
     */
    @Override
    public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
        return content;
    }
}
